package org.activequant.tradesystem.ib;

import org.activequant.core.domainmodel.account.Order;

/**
 * Part of tradesystem that implements strategy of entering a position
 * and exit policy.
 * <p>
 * An interface. Defines the following method:
 * <ul>
 * <li>IPositionTracker openPosition(Order order)</li>
 * </ul>
 * It also defines a nested IPositionTracker interface.
 */
public interface IPositionService {
	
	/**
	 * Handler to control opened position (or position in
	 * the process of opening). This handler is used by
	 * trading system to follow-up on the position.
	 * The only action possible is closing the position.<br/>
	 * A nested interface. Defines the following method(the others are commented out):
	 * <ul>
	 * <li>void close()</li>
	 * <li>boolean isClosed()</li>
	 * <li>boolean hasMainOrderReachedMaximumInactivePeriod()</li>
	 * <li>boolean hasStopOrderReachedMaximumInactivePeriod()</li>
	 * <li>boolean hasStopOrderReachedMaximumInactivePeriod()</li>
	 * <li>void placeBracketOrders()</li>
	 * <li>double getMainOrderFilledQuantity()</li>
	 * <li>double getStopOrderFilledQuantity()</li>
	 * <li>double getLimitOrderFilledQuantity()</li>
	 * <li>IOrderTracker getMainOrderTracker()</li>
	 * <li>IOrderTracker getStopOrderTracker()</li>
	 * <li>IOrderTracker getLimitOrderTracker()</li>
	 * </ul>
	 */
	public interface IPositionTracker {

		/**
		 * Describes position's side.
		 * 
		 * @return side.
		 */
//		Order.Side getSide();
		
		/**
		 * Filled quantity. May be zero if position was not opened yet
		 * (order not executed or canceled).
		 * 
		 * @return quantity.
		 */
		double     getQuantity();
		
		/**
		 * Average fill price. Zero if position is not yet opened.
		 * 
		 * @return price.
		 */
//		double     getPrice();
		
		/**
		 * Closes the position. Strategy implements the way of
		 * closing the position.
		 */
		void close();
		
		/**
		 * Returns <code>true</code> if position has been (automatically)
		 * closed.
		 * 
		 * @return true if closed.
		 */
		 boolean isClosed();		
		 
//		 void placeBracketOrders();

	}

	/**
	 * Opens a position. This method returns immediately,
	 * but position is being populated asynchronously.
	 * 
	 * @param order order describing position.
	 * @return position handler (tracker).
	 */
	public IPositionTracker openPosition(Order order);
	
}